﻿#region Copyright(c) 2006 ZO, All right reserved.

// -----------------------------------------------------------------------------
// Copyright(c) 2006 ZO, All right reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//   1.  Redistribution of source code must retain the above copyright notice,
//       this list of conditions and the following disclaimer.
//   2.  Redistribution in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//   3.  The name of the author may not be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// -----------------------------------------------------------------------------

#endregion

#region Using directives

using System.Collections;
using System.Collections.Generic;
using ZO.SmartCore.Collections.Generic;

#endregion

namespace ZO.SmartCore.Configuration
{
    /// <summary>
    /// Collection of Section Keys
    /// </summary>
    public sealed class SectionKeyCollection : IEnumerable<SectionKey>
    {
        #region Constructors

        #endregion

        #region Destructor

        #endregion

        #region Fields

        private OrderedDictionary<string, SectionKey> keys = new OrderedDictionary<string, SectionKey>();

        #endregion

        #region Events

        #endregion

        #region Operators

        #endregion

        #region Properties

        /// <summary>Gets the <see cref="System.Collections.Generic.IEqualityComparer{T}"></see> that is used to determine equality of keys for the dictionarytable. </summary>
        /// <returns>The <see cref="System.Collections.Generic.IEqualityComparer{T}"></see> generic interface implementation that is used to determine equality of keys for the current <see cref="T:System.Collections.Generic.Dictionary`2"></see> and to provide hash values for the keys.</returns>
        public IEqualityComparer<string> Comparer
        {
            get { return this.keys.Comparer; }
        }

        /// <summary>
        /// Gets the count.
        /// </summary>
        /// <value>The count.</value>
        public int Count
        {
            get { return this.keys.Count; } // get
        }

        /// <summary>
        /// Gets an collection containing the values of the <see cref="System.Collections.Generic.IDictionary{TKey, TValue}"></see>.
        /// </summary>
        /// <value></value>
        /// <returns>An collection containing the values of the object that implements <see cref="System.Collections.Generic.IDictionary{TKey, TValue}"></see>.</returns>
        public ICollection<string> Keys
        {
            get { return keys.Keys; }
        }

        /// <summary>
        /// Gets an collection containing the values in the <see cref="System.Collections.Generic.IDictionary{TKey, TValue}"></see>.
        /// </summary>
        /// <value></value>
        /// <returns>An collection containing the values in the object that implements <see cref="System.Collections.Generic.IDictionary{TKey, TValue}"></see>.</returns>
        public ICollection<SectionKey> Values
        {
            get { return keys.Values; } // get
        }

        /// <summary>
        /// Gets or sets the value with the specified key.
        /// </summary>
        /// <value></value>
        public SectionKey this[string key]
        {
            get { return this.keys[key]; }
            set { this.keys[key] = value; }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Adds the key with specified name.
        /// </summary>
        /// <param name="name">The name.</param>
        public void Add(string name)
        {
            keys.Add(name, new SectionKey(name));
        } // Add

        /// <summary>
        /// Adds the key with specified name.
        /// </summary>
        /// <param name="newSectionKey">The new section key.</param>
        public void Add(SectionKey newSectionKey)
        {
            keys.Add(newSectionKey.Name, newSectionKey);
        } // Add

        /// <summary>
        /// Adds the key with specified name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="value">The value.</param>
        public void Add(string name, string value)
        {
            keys.Add(name, new SectionKey(name, value));
        } // Add

        /// <summary>
        /// Adds the key with specified name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="value">The value.</param>
        /// <param name="comment">The comment.</param>
        public void Add(string name, string value, string comment)
        {
            keys.Add(name, new SectionKey(name, value, comment));
        } // Add

        /// <summary>
        /// Removes the specified name.
        /// </summary>
        /// <param name="name">The name.</param>
        public void Remove(string name)
        {
            keys.Remove(name);
        } // Add

        /// <summary>
        /// Removes all keys and values from the Dictionary. 
        /// </summary>
        public void Clear()
        {
            keys.Clear();
        } // Clear

        /// <summary>
        /// Determines whether the dictionary contains specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns>
        /// 	<c>true</c> if the specified key contains key; otherwise, <c>false</c>.
        /// </returns>
        public bool ContainsKey(string key)
        {
            return keys.ContainsKey(key);
        } // ContainsKey

        /// <summary>
        /// Determines whether the specified value contains value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>
        /// 	<c>true</c> if the specified value contains value; otherwise, <c>false</c>.
        /// </returns>
        public bool ContainsValue(SectionKey value)
        {
            return this.keys.ContainsValue(value);
        } // ContainsValue

        /// <summary>
        /// Determines whether [contains] [the specified key].
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns>
        /// 	<c>true</c> if [contains] [the specified key]; otherwise, <c>false</c>.
        /// </returns>
        public bool Contains(string key)
        {
            return keys.ContainsKey(key);
        } // ContainsKey

        /// <summary>
        /// Tries the get value.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public bool TryGetValue(string key, out SectionKey value)
        {
            return keys.TryGetValue(key, out value);
        } // TryGetValue

        #endregion

        #region IEnumerable<SectionKey> Members

        /// <summary>
        /// Returns an enumerator that iterates through the collection.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.Collections.Generic.IEnumerator`1"></see> that can be used to iterate through the collection.
        /// </returns>
        public IEnumerator<SectionKey> GetEnumerator()
        {
            return this.keys.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        /// <summary>
        /// Returns an enumerator that iterates through a collection.
        /// </summary>
        /// <returns>
        /// An <see cref="T:System.Collections.IEnumerator"></see> object that can be used to iterate through the collection.
        /// </returns>
        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.keys.GetEnumerator();
        }

        #endregion
    }
}